import Vue from "vue"
import VueRouter from "vue-router";
import routes from '@/router/routes'

// const Home = () => import("@/views/Home")
// const Dictionary = () => import("@/views/system/Dictionary")
// const Login = () => import("@/views/Login")

Vue.use(VueRouter)


/*const routes = [{
	path: "/",
	redirect: "home"
}, {
	path: "/login",
	name: "login",
	component: Login
}, {
	name: "home",
	path: "/home",
	component: Home,
	meta: {
		title: "首页"
	},
	children: [{
		name: "organization",
		path: "/org",
		component: () => import("@/views/system/Organization"),
		meta: {
			title: "组织机构管理"
		}
	}, {
		name: "usermanager",
		path: "/usermanager",
		component: () => import("@/views/system/SysUser"),
		meta: {
			title: "用户管理"
		}
	},{
		name: "dict",
		path: "/dict",
		component: Dictionary,
		meta: {
			title: "字典管理"
		}
	}, {
		path: "/dict/:action",
		component: () => import("@/views/system/DictCategoryForm")
	}]
}]*/


const router = new VueRouter({
	mode: "history",
	routes
})

router.beforeEach((to, from, next) => {
	if (to.path == "/login") {
		next();
	} else {
		if (sessionStorage.getItem("isAuth") === "true") {
			next();
		} else {
			next({
				path: "/login",
				query: {
					redirect: to.fullPath
				}
			})
		}
	}
})

export default router
